﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mimoza.Transport;

namespace Mimoza.AgentLayer.Communication
{
    public class RequestUpdatesFileChunk : TransferObjectGeneric<RequestUpdatesFileChunk, ReplyUpdatesFileChunk>
    {
        const int c_DefaultChukSize = 1024 * 32;

        public RequestUpdatesFileChunk()
        {
        }

        public RequestUpdatesFileChunk(Guid updateId, int pos)
        {
            Init(updateId, pos, c_DefaultChukSize);
        }

        public RequestUpdatesFileChunk(Guid updateId, int pos, int needSize)
        {
            Init(updateId, pos, needSize);
        }

        private void Init(Guid updateId, int pos, int needSize)
        {
            UpdateId = updateId; 
            Position = pos; 
            NeedSize = needSize;
        }

        public Guid UpdateId
        {
            get { return m_updateId; }
            set { m_updateId = value; }
        }

        public int Position
        {
            get { return m_position; }
            set { m_position = value; }
        }

        public int NeedSize
        {
            get { return m_needSize; }
            set { m_needSize = value; }
        }

        Guid m_updateId;
        int m_position = 0;
        int m_needSize = 0;
    }


    public class ReplyUpdatesFileChunk : TransferObjectGenericReply<ReplyUpdatesFileChunk>
    {
        public ReplyUpdatesFileChunk()
        {
        }

        public ReplyUpdatesFileChunk(int position, byte[] body, bool bEof)
        {
            Position = position;
            Body = body;
            EndOfFile = bEof;
        }

        public byte[] Body
        {
            get { return m_body; }
            set { m_body = value; }
        }
        
        public int Position
        {
            get { return m_position; }
            set { m_position = value; }
        }

        public int ChunkSize
        {
            get { return (m_body==null)? 0 : m_body.Length; }
        }

        public bool EndOfFile
        {
            get { return m_bEof; }
            set { m_bEof = value; }
        }

        byte[] m_body = null;
        int m_position = 0;
        bool m_bEof = false;
    }
}
